<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ include file="/common/taglib.jsp" %>

<!doctype html>
<html lang="ko">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title><spring:message code="main.title"/></title>
<link href="/css/reset.css" type="text/css" rel="stylesheet" />
<link href="/css/common.css" type="text/css" rel="stylesheet" />
<link href="/css/layout.css" type="text/css" rel="stylesheet" />
<link href="/css/ui.css" type="text/css" rel="stylesheet" />
<script src="/js/jquery.min.js"></script>
<script src="/js/jquery-ui-1.10.4.custom.min.js" type="text/javascript"></script>
<!--script src="/js/gnb.min.js" type="text/javascript"></script-->
<script src="/js/gnb_ui.js" type="text/javascript"></script>
<script src="/js/left_menu.js" type="text/javascript"></script>
<script src="/js/ui.js" type="text/javascript"></script>

<script>
	//댑스별 메뉴 활성화
	var navCurrentParam1 = ${boardInfo.boardId};//1depth
	var navCurrentParam2 = 0;//2depth
	var navCurrentParam3 = 0;//3depth
</script>
<script type="text/javascript">
$(document).ready(function() {
	
});

//목록
function fncList(){
	window.location.href="/board/contentsList.do?boardId=${boardInfo.boardId}";
}

//상세폼
function viewForm(contentsGroupId){
	window.location.href="/board/contentsView.do?contentsGroupId="+contentsGroupId;
}

//갱신폼
function updateForm(contentsSeq){
	$("#viewType").val("update");
	$("#contentsSeq").val(contentsSeq);
	$("#searchVO").submit();
}
//삭제
function deleteData(contentsSeq){
	$("#contentsSeq").val(contentsSeq);
	$.post("/admin/deleteContents.do", $("#searchVO").serialize(),
	        function(data){
	        	if (data.success == "true"){
	        		alert('게시물을 삭제하였습니다.');
	        		$('#searchVO').attr('action', "/board/contentsList.do");
	        		$("#searchVO #contentsGroupId").val(0);
					$("#searchVO #contentsSeq").val(0);
					$("#searchVO #page").val(1);
					$('#searchVO').submit();
	        	}else{
	        		alert(data.message);
	        	}
	        }, "json"
	    );
}
var checkType = "";

function userDelete(contentsSeq) {
	$("#contentsSeq").val(contentsSeq);
	checkType = "delete";
	fncOpenPasswordPopup();
}

function userUpdate(contentsSeq) {
	$("#contentsSeq").val(contentsSeq);
	checkType = "update";
	fncOpenPasswordPopup();
}

function fncOpenPasswordPopup() {
	var top = 400;
	var left = eval(window.screen.width)/2 - 150;
	var popOption = "width=400, height=150, left=0, resizable=no , toolbars = no, top="+top+", left="+left+", scrollbars=no, status=no;"; // 팝업창
	window.open("/board/popup.do", "BOARD_POPUP", popOption);
}

function fncPasswordCheck(password) {
	$("#password").val(password);
	$.post("/board/checkPassword.do", $("#searchVO").serialize(),
	        function(data){
	        	if (data.success == "true"){
	        		if(checkType == "delete") {
		        		if(confirm("게시물을 삭제하시겠습니까?")) {
		        			fncUserDelete();
		        		}
	        		} else {
	        			fncUserUpdate();
	        		}
	        		
	        	}else{
	        		alert(data.message);
	        	}
	        }, "json"
	    );
}

function fncUserDelete() {
	$.post("/board/deleteContents.do", $("#searchVO").serialize(),
	        function(data){
	        	if (data.success == "true"){
	        		alert('게시물을 삭제하였습니다.');
	        		$('#searchVO').attr('action', "/board/contentsList.do");
					$("#searchVO #page").val(1);
					$("#searchVO #contentsGroupId").val(0);
					$("#searchVO #contentsSeq").val(0);
					$('#searchVO').submit();
	        	}else{
	        		alert(data.message);
	        	}
	        }, "json"
	    );
}

function fncUserUpdate() {
	$('#searchVO').attr('action', "/board/contentsForm.do");
	$("#viewType").val("update");
	$("#searchVO").submit();
}

function replyDelete(contentsSeq) {
	$("#contentsSeq").val(contentsSeq);
	$.post("/admin/deleteContents.do", $("#searchVO").serialize(),
	        function(data){
	        	if (data.success == "true"){
	        		alert('게시물을 삭제하였습니다.');
	        		$('#searchVO').attr('action', "/board/contentsList.do");
	        		$("#searchVO #page").val(1);
	        		$("#searchVO #contentsGroupId").val(0);
					$("#searchVO #contentsSeq").val(0);
					$('#searchVO').submit();
	        	}else{
	        		alert(data.message);
	        	}
	        }, "json"
	    );
}

function replyUpdate(contentsSeq) {
	$("#viewType").val("update");
	$("#contentsSeq").val(contentsSeq);
	$("#searchVO").submit();
}

function replyRegist() {
	$("#viewType").val("reply");
	$("#searchVO").submit();
}

function mapView(contentsId, attachFileSeq) {
	var popUrl = "/board/mapViewer.do?contentsId=" + contentsId + "&attachFileSeq="+attachFileSeq;
	var popOption = "width=800, height=700, left=0, resizable=no , toolbars = no, top=0, scrollbars=no, status=no;"; // 팝업창
																												// 옵션(optoin)
	window.open(popUrl, "BOARD_MAP_VIEWER", popOption);
}


</script>
<c:set var="navCurrentParam1" value="${searchVO.boardId}" scope="request" />
</head>
<body>
<form:form commandName="searchVO" name="searchVO" action="/admin/contentsForm.do" method="get">
	<form:hidden path="boardId"/>
	<form:hidden path="contentsGroupId"/>
	<form:hidden path="contentsSeq"/>
	<input type="hidden" id="password" name="password" />
	<input type="hidden" id="viewType" name="viewType" />		
</form:form>
<!-- 메뉴건너뛰기 -->
<div id="skipnavigation">
	<a href="#header">상단메뉴 바로가기</a>
	<a href="#container">컨텐츠 바로가기</a>
	<a href="#footer">하단 바로가기</a>
</div>
<!-- //메뉴건너뛰기 -->
<div class="wrap">
	<!-- Header -->
	<jsp:include page="../common/header.jsp"></jsp:include>
	<!--// Header -->
	<!-- 컨텐츠 -->
	<div id="container" class="bg_sub">
		<div class="sub_wrap">
			<!-- 내용영역 -->
			<div class="sub_content">
				<div class="left_menu">
					<c:if test="${boardInfo.boardId gt 2}">
						<h2>
							<img src="/img/leftMenu7.png" alt="참여서비스" />
						</h2>
					</c:if>
					<c:if test="${boardInfo.boardId lt 3}">
						<h2>
							<img src="/img/leftMenu6.png" alt="시청각자료" />
						</h2>
					</c:if>
					<!-- left 메뉴 -->
					<div id="left">
						<c:if test="${boardInfo.boardId gt 2}">
							<ul class="navmenu navmenu7">
								<li class="nvparam3"><a
									href="/board/contentsList.do?boardId=3">공지사항</a></li>
								<li class="nvparam4"><a
									href="/board/contentsList.do?boardId=4">묻고답하기</a></li>
							</ul>
						</c:if>
						<c:if test="${boardInfo.boardId lt 3}">
							<ul class="navmenu navmenu6">
								<li class="nvparam1"><a
									href="/board/contentsList.do?boardId=1">추천컨텐츠</a></li>
								<li class="nvparam2"><a
									href="/board/contentsList.do?boardId=2">지역정보</a></li>
							</ul>
						</c:if>
						</div>
				</div>
				<div class="sub_area">
					<!-- 서브 네비게이션 -->
					<ul class="sub_navi">
						<li><a href="/"><img src="/img/sub_navi1.gif" alt="home"/></a></li>
						<li ${boardInfo.boardId == '1' ? "class='sel_navi'" : ""}><a href="/board/contentsList.do?board=01">시청각 자료</a></li>
						<li ${boardInfo.boardId == '2' ? "class='sel_navi'" : ""}><a href="/board/contentsList.do?board=02">지역정보</a></li>
					</ul>
					<!-- //서브 네비게이션 -->
					<div class="sub_tit">
						<h3><img src="/img/subMenu_tit0${boardInfo.boardId}.gif" alt="지역정보"/></h3>
					</div>
					<c:if test="${boardInfo.boardTypeCd eq '01' }">
					<div class="tab_tit">
						<h4>${contentsGroupList[0].contentsNm}</h4>
					</div>
					<div id="tabs">
						<!-- 지역개관 -->
						
						<div id="tabs-1">
							<c:out value="${contentsGroupList[0].contentsDesc}" escapeXml="false" />
						</div>
						<!-- //지역개관 --> 
						
					</div>
					</c:if>
					<!-- 탭메뉴 -->
					<c:if test="${boardInfo.boardTypeCd eq '02' }">
					<div class="tab_tit">
						<h4>${contentsGroupList[0].contentsNm}</h4>
					</div>
					<div id="tabs">
						<ul>
							<li><a href="#tabs-1">지역개관</a></li>
							<li><a href="#tabs-2">주제도</a></li>
						</ul>
						<!-- 지역개관 -->
						<div id="tabs-1">
							<c:out value="${contentsGroupList[0].contentsDesc}" escapeXml="false" />
						</div>
						<!-- //지역개관 --> 
						<!-- 주제도 -->
						<div id="tabs-2">
							<c:forEach var="attachFile" items="${contentsGroupList[0].attachFileList}">
							<c:if test="${attachFile.attachFileTypeCd eq '01'}">
							<h4>${attachFile.attachFileDesc }</h4>
							<div class="mapImg">
								<a href="javascript:mapView('${attachFile.contentsId }', '${attachFile.attachFileSeq}')"><img src="/download.do?contentsId=${attachFile.contentsId }&attachFileSeq=${attachFile.attachFileSeq}&thumbnail=true"/></a>
							</div>
							</c:if>
							</c:forEach>
						</div>
						<!-- //주제도 -->
					</div>
					</c:if>
					<c:if test="${boardInfo.boardTypeCd eq '03'}">
					<div class=" ">
					<div class="tb_sch_view">
							<table>
								<colgroup>
									<col style="width:105px;"/><col/><col style="width:105px;"/><col/>
								</colgroup>
								<tbody>
									<tr>
										<th scope="row">제목</th>
										<td colspan="5">
											<div class="clearfix">
												<p class="f_left">${contentsGroupList[0].contentsNm }</span>
											</div>
										</td>
									</tr>
									<tr>
										<th scope="row">등록일</th>
										<td>
											<fmt:formatDate value="${contentsGroupList[0].writeDate}" pattern="yyyy.MM.dd"/>
										</td>
										<th scope="row">작성자</th>
										<td>
											${contentsGroupList[0].writerNm}
										</td>
										<th scope="row">조회수</th>
										<td>
											${contentsGroupList[0].viewCnt}
										</td>
									</tr>
									<tr>
										<td scope="col" colspan="6">
											<div class="reple_wrap">
												<p class="reple_tit"><strong>[질문]${contentsGroupList[0].contentsNm }</strong></p>
												<p>${contentsGroupList[0].contentsDesc }</p>
												<c:if test="${fn:length(contentsGroupList[0].attachFileList) gt 0}" >
													<div class="file_reple">
														<c:forEach var="attachFile" items="${contentsGroupList[0].attachFileList }">
														<span><a href="#">${attachFile.attachFileOriginNm }</a></span>
														</c:forEach>
													</div>
												</c:if>
												<c:if test="${fn:length(contentsGroupList) gt 1}">
												<div class="reple_area">
													<p class="reple_tit"><strong>[답변]${contentsGroupList[1].contentsNm }</strong> <em>(<fmt:formatDate value="${contentsGroupList[1].writeDate}" pattern="yyyy.MM.dd"/>)</em></p>
													${contentsGroupList[1].contentsDesc }
													<c:if test="${fn:length(contentsGroupList[1].attachFileList) gt 0}" >
													<div class="file_reple">
														<c:forEach var="attachFile" items="${contentsGroupList[1].attachFileList }">
														<span><a href="#">${attachFile.attachFileOriginNm }</a></span>
														</c:forEach>
													</div>
													</c:if>
												</div>
												</c:if>
											</div>
										</td>
									</tr>
								</tbody>
							</table>
						</div>
					</div>
					</c:if>
					<c:if test="${boardInfo.boardTypeCd eq '04' }">
					<div class=" ">
					<div class="tb_sch_view">
							<table>
								<colgroup>
									<col style="width:105px;"/><col/><col style="width:105px;"/><col/>
								</colgroup>
								<tbody>
									<tr>
										<th scope="row">제목</th>
										<td colspan="3">
											<div class="clearfix">
												<p class="f_left">${contentsGroupList[0].contentsNm }</span>
											</div>
										</td>
									</tr>
									<tr>
										<th scope="row">등록일</th>
										<td>
											<fmt:formatDate value="${contentsGroupList[0].writeDate}" pattern="yyyy.MM.dd"/>
										</td>
										<th scope="row">조회수</th>
										<td>
											${contentsGroupList[0].viewCnt}
										</td>
									</tr>
									<tr>
										<td scope="col" colspan="4">
											<div class="reple_wrap">
												<p class="reple_tit"><strong>${contentsGroupList[0].contentsNm }</strong></p>
												${contentsGroupList[0].contentsDesc }
											</div>
										</td>
									</tr>
								</tbody>
							</table>
						</div>
					</div>
					</c:if>
					<!-- //탭메뉴 -->
					<!-- 버튼 -->
					<div class="btn_area">
						<div class="t_right">
							<a href="javascript:fncList()" class="btn_list_view"><span>목록</span></a>
						</div>
						<c:choose>
						<c:when test="${boardInfo.boardTypeCd eq '03'}">
							<div class="t_right">
								<c:choose>
								<c:when test="${fn:length(contentsGroupList) gt 1}">
									<a href="javascript:alert('답변이 등록된 게시물은 삭제 할 수 없습니다.')" class="btn_list_view"><span>삭제</span></a>
								</c:when>
								<c:otherwise>
									<a href="javascript:userDelete('${contentsGroupList[0].contentsSeq }')" class="btn_list_view"><span>삭제</span></a>
								</c:otherwise>
							</c:choose>
							</div>
							<div class="t_right">
								<a href="javascript:userUpdate('${contentsGroupList[0].contentsSeq }')" class="btn_list_view"><span>수정</span></a>
							</div>
						<c:if test="${loginChk}">
							<c:choose>
							<c:when test="${fn:length(contentsGroupList) gt 1}">
							<div class="t_right">
								<a href="javascript:replyDelete('${contentsGroupList[1].contentsSeq }')" class="btn_list_view"><span>답변 삭제</span></a>
							</div>
							<div class="t_right">
								<a href="javascript:replyUpdate('${contentsGroupList[1].contentsSeq }')" class="btn_list_view"><span>답변 수정</span></a>
							</div>
							</c:when>
							<c:otherwise>
							<div class="t_right">
								<a href="javascript:replyRegist()" class="btn_list_view"><span>답변 등록</span></a>
							</div>
							</c:otherwise>
							</c:choose>
						</c:if>
					</c:when>	
					<c:otherwise>
						<c:if test="${loginChk}">
						<div class="t_right">
							<a href="javascript:deleteData('${contentsGroupList[0].contentsSeq }')" class="btn_list_view"><span>삭제</span></a>
						</div>
						<div class="t_right">
							<a href="javascript:updateForm('${contentsGroupList[0].contentsSeq }')" class="btn_list_view"><span>수정</span></a>
						</div>
						</c:if>
						</c:otherwise>
						</c:choose>
					</div>
					<!-- //버튼 -->
				</div>
			</div>
			<!-- //내용영역 -->
		</div>
	</div>
	<!-- //컨텐츠 -->
	<!-- 하단 -->
	<jsp:include page="../common/footer.jsp"></jsp:include>
	<!-- //하단 -->
</div>
<script type="text/javascript">
//<![CDATA[
(function ($) {
	$(document).ready(function() {
		//검색창
		$('.search').schSelect();
		//gnb 메뉴
		navigation("gnb_wrap", "slide");
		//탭메뉴
		$( "#tabs" ).tabs();
	});
}(jQuery));
//]]>
</script>
</body>
</html>